import BaseModel from './BaseModel'

import DataModel from 'framework/datamodel';

export default class DataSetModel extends BaseModel {
  total = 0;
  static type = 'data.set';
  datas = [];

  constructor(data = null) {
    super(data);
    if (data !== null) {
      this.model(data);
    }
  }

  model(data) {
    if (data.hasOwnProperty('datas')) {
      let datas = [];
      for (let dataItem of data['datas']) {
        if (DataModel.hasModel(dataItem.type)) {
          datas.push(DataModel.buildModel(dataItem.type, dataItem));
        } else {
          datas.push(dataItem);
        }

      }
      data['datas'] = datas;
    }

    super.model(data);

  }

  * dataSet() {
    for (let data of this.datas) {
      yield data;
    }
  }

}
